<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <#include "/pubHeadStyle.html">
</head>
<body>
<script type="text/html" id="gennerTabTool">
    <div class="generSearch">
        <form class="layui-form" action="" style="margin-top:10px" lay-filter="generForm">
            <div class="table-top-filter" style="position: relative">
                <div class="table-filter-alone">
                    <label class="layui-form-label">表名</label>
                    <input type="text" id="tableName" lay-verify="required" name="Q_tableName_SL"
                           class="layui-input filter-value" autocomplete="off" placeholder="表名"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">注释</label>
                    <input type="text" id="tableDesc" lay-verify="required" name="Q_tableDesc_SL" autocomplete="off"
                           class="layui-input filter-value" placeholder="注释">
                </div>
            </div>
            <a class="layui-btn layui-btn-sm" id="query" lay-event="query"
               style="position: absolute;top: 4px;right: 168px;">
                <i class="layui-icon layui-icon-search"></i>
                <span>查询</span>
            </a>
        </form>
    </div>
</script>
<div style="width: 100%;" class="generTableSize">
    <table class="layui-hide" id="gennerTab" lay-filter="gennerTab"></table>
</div>
<div class="layui-form-item" style="border:none;margin-bottom:0">
    <div class="layui-input-block" style="margin:0">
        <div class="layui-footer" style="text-align: center;padding-top: 10px">
            <button type="button" class="layui-btn layui-btn-sm" id="choose">选择</button>
            <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" id="returnCol">取消</button>
        </div>
    </div>
</div>
<div class="addSer" hidden>
</div>
<input type="hidden" id="parentName" name="parentName" value="${parentName}">
<script>
    layui.config({
        base: serverPath.formPath + staticPath.formPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index', 'form', 'layedit', 'laydate', 'jquery', 'table', 'setter', 'totalFilter', 'common'], function () {
        var form = layui.form;
        var table = layui.table;
        var $ = layui.$;
        var setter = layui.setter, totalFilter = layui.totalFilter, common = layui.common;
        //关闭弹窗
        var index = parent.layer.getFrameIndex(window.name);
        $("#returnCol").on('click', function () {
            parent.layer.close(index);
        });
        table.render({
            elem: '#gennerTab'
            , url: serverPath.formPath + setter.formLinkPath + "table/list"
            , toolbar: '#gennerTabTool'
            , defaultToolbar: []
            , height: 'full-61'
            , cols: [[
                {type: 'radio'}
                , {field: 'tableName', title: '表名'}
                , {field: 'tableDesc', title: '注释'}
                , {field: 'subStr', title: '子表信息',hide:true}
            ]]
            , where: {
                isMain: 1,
                isPublished: 1
            }
            , page: true
        });
        totalFilter.init('gennerTab');
        var mainTableId;
        var mainTableName;
        var subStr;
        table.on('radio', function (data) {
            mainTableId = data['data']['tableId'];
            mainTableName = data['data']['tableName'];
            subStr = data['data']['subStr'];
        });

        $("#choose").on('click', function (data) {
            parent.$('#mainTableId').val(mainTableId);
            parent.$('#mainTableName').val(mainTableName);
            //判断是否为空或者是未定义; 添加表单的表赋值
            var parentName = $("#parentName").val();
            if (parentName != "" && parentName != undefined) {
                var ifr = window.parent.frames[parentName];
                var win = ifr.window || ifr.contentWindow;
                win.document.getElementById("mainTableId").value = mainTableId;
                win.document.getElementById("subStr").value = subStr;
                if(mainTableName != undefined){
                    win.document.getElementById("mainTableName").value = mainTableName;
                }
            }
            parent.layer.close(index);
        });
        //头工具栏事件
        table.on('toolbar(gennerTab)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data; //获取选中行数据
            switch (obj.event) {
                case 'query':
                    common.tableConditionRender("gennerTab", "generForm", {
                        where: {
                            isMain: '1',
                            isPublished: '1'
                        }
                    }, false);
                    break;
            }
        });
    });
</script>
<style>
    .generTableSize .layui-table-view{
        height: 405px !important;
    }
</style>
</body>
</html>